<template>
    <div class="rentNote">
        <el-table :data="rentNode.rentList" style="width: 100%" @selection-change="selhandle">
            <el-table-column type="selection" width="55" />
            <el-table-column prop="Cordid" label="租借数量">
                <template #default="scope">
                    <span>1</span>
                </template>
            </el-table-column>
            <el-table-column prop="Currinvent" label="当前库存" width="150" />
            <el-table-column prop="Create_time" label="起始时间">
                <template #default="scope">
                    <span>{{ scope.row.Create_time.slice(0, 10) + "/" + scope.row.Create_time.slice(11, 19) }}</span>
                </template>
            </el-table-column>
            <!-- <span>{{ scope.row.Inputdata.slice(0, 10) + "/" + scope.row.Inputdata.slice(11, 19) }}</span> -->
            <el-table-column prop="Currten_time" label="截止时间">
                <template #default="scope">
                    <span>{{ scope.row.Currten_time.slice(0, 10) + "/" + scope.row.Currten_time.slice(11, 19) }}</span>
                </template>
            </el-table-column>
            <el-table-column prop="Isreturned" label="是否同意">
                <template #default="scope">
                    <span>
                        {{ scope.row.Isreturned == "1" ? '已同意' : '未同意' }}
                    </span>
                </template>
            </el-table-column>
            <el-table-column prop="Name" label="删除记录">
                <template #default="scope">
                    <el-popconfirm title="确认删除?" @confirm="delRent(scope.row.Cordid)">
                        <template #reference>
                            <el-button type="danger">删除</el-button>
                        </template>
                    </el-popconfirm>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script setup>
import { ref, reactive, toRefs } from 'vue';
import { rentNodeApi, delrentNodeApi } from "../request/api";
import { useRoute, useRouter } from "vue-router";
import { rentNodeStore } from "../store/rentNode";

const Router = useRouter();
const Route = useRoute();
const rentNode = reactive(rentNodeStore())

let rentList = reactive([]);
// Cordid: 2
// Create_time: "2023-03-21T21:57:09+08:00"
// Currinvent: 95
// Currten_time: "2023-03-27T15:23:04+08:00"
// Id: 1
// Isreturned: "1"
// 加载数据
rentNodeApi().then(res => {
    rentNode.addrentList(res);
})
// 选中操作
const selhandle = (val) => {
    console.log(val);
}
// 删除租借记录
const delRent = (val) => {
    console.log(val);
    delrentNodeApi(val).then(res => {
        console.log(res);
        if (res.askData.prompt == "Deleted") {
            ElMessage({
                message: "删除成功！",
                type: 'success'
            });
            setTimeout(() => {
                Router.go(0)
            }, 1000)
        } else {
            ElMessage({
                message: "删除失败！",
                type: 'error'
            });
        }
    })
}
</script>
 
<style lang = "less" scoped>
:deep(.el-table .cell) {
    text-align: center;
}

// is-leaf
:deep(.el-table .is-leaf .cell) {
    color: #000;
    font-weight: 700;
}
</style>